var BaseObject = gg.module('BaseObject');

var Shape = BaseObject.extend({
    /**
     * 计算形状的面积
     */
    area: function() {
        return 0;
    },
    /**
     * 判断点是否在形状范围内
     * @param {Point} p 点位置
     */
    hasPoint: function(p) {
        var center = this.get('center');
        return (p.x == center.x && p.y == center.y) ? true : false;
    },
    /**
     * 中心点到中心点的距离
     * @param {shape.Base | Point} shape
     */
    distance: function(shape) {
        var center1 = this.get('center'), center2 = shape;
        if (p instanceof Shape) {
            center2 = p.get('center');
        }
        var dx = center1.x - center2.x, dy = center1.y - center2.y;
        return Math.sqrt(dx * dx - dy * dy);
    }
});

Shape.metadata = _.extend({}, BaseObject.metadata, {
    center: {
        label: '中心点',
        type: 'datatype.Position',
        defaultValue: {x: 0, y: 0}
    }
});

module.exports = Shape;
